# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=gegl
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=0.4.2
pkgrel=1
pkgdesc="Generic Graphics Library (mingw-w64)"
arch=('any')
url="http://gegl.org/"
license=("GPL-3.0+" "LGPL-3.0+")
makedepends=("asciidoc"
             "intltool"
             #"${MINGW_PACKAGE_PREFIX}-ffmpeg"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-lua"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-ruby"
             "${MINGW_PACKAGE_PREFIX}-vala")
depends=("${MINGW_PACKAGE_PREFIX}-babl"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-exiv2"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gtk2"
         "${MINGW_PACKAGE_PREFIX}-jasper"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-LibRaw"
         "${MINGW_PACKAGE_PREFIX}-librsvg"
         "${MINGW_PACKAGE_PREFIX}-libspiro"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-lcms"
         "${MINGW_PACKAGE_PREFIX}-lensfun"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-SDL"
         "${MINGW_PACKAGE_PREFIX}-suitesparse")
#optdepends=("${MINGW_PACKAGE_PREFIX}-openexr: for using the openexr plugin"
#            "${MINGW_PACKAGE_PREFIX}-ffmpeg: for using the ffmpeg plugin"
#            "${MINGW_PACKAGE_PREFIX}-librsvg: for using the svg plugin"
#            "${MINGW_PACKAGE_PREFIX}-jasper: for using the jasper plugin")
#options=('!strip' 'debug')
source=(#"${_realname}"::"git+https://git.gnome.org/browse/gegl"
        https://ftp.gtk.org/pub/gegl/${pkgver%.*}/${_realname}-${pkgver}.tar.bz2)
sha256sums=('6a358bc19d20b8ac1daf645cc8b53cdc2ea6f9c98a6036179a57045a26a07f8d')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  #autoreconf --force --install --verbose
}

build() {
  declare -a extra_config

  if check_option "debug" "y"; then
    extra_config+=("--enable-debug")
    VERBOSE="V=1"
    export DISTUTILS_DEBUG=1
  fi

  export lt_cv_deplibs_check_method='pass_all'

  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --disable-static \
    --with-sdl \
    --with-openexr \
    --with-librsvg \
    --with-jasper \
    --without-libavformat \
    --disable-docs \
    --with-vala \
    --enable-introspection \
    "${extra_config[@]}"

  make ${VERBOSE}
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
  rm "${pkgdir}${MINGW_PREFIX}"/lib/gegl-*/*.dll.a
}
